//
//  MoreViewController.m
//  NetPhone
//
//  Created by intel intel on 12-4-28.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "MoreViewController.h"
#import "AppDelegate.h"
#import "ModiPwdViewController.h"
#import "FindPwdViewController.h"

#import "GlobalVar.h"
#import "iToast.h"
#import "Common.h"
#import "WebViewController.h"

#import "BangDing_ViewControl.h"
#import "PayViewController.h"
#import "WebView_ViewController.h"
#import "VisitWebViewController.h"
#import "DisPayContentViewController.h"
#import "DisPayViewController.h"
#import "KeyboardView.h"
#import "CallRecordViewController.h"
#import "DialSettingViewController.h"
#import "LocalDisNumSetViewController.h"
#import "GlobalVar.h"
#import "QrCodeView.h"
#import "RecordCallingTimeViewCtrl.h"
//#import "ipjsua_app_callback.h"
#import "ViewController.h"



@implementation MoreViewController


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];

    self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
    self.title = @"更多";
    NSString* qrCodeStr = [[NSUserDefaults standardUserDefaults]objectForKey:@"qrCodeStr"];
    //@"账户充值",
    if (qrCodeStr.length>3)
    {
        rows = [[NSArray arrayWithObjects:
                 [NSArray arrayWithObjects:@"最新优惠",@"推荐好友", nil],
                 [NSArray arrayWithObjects:@"查询余额",@"修改密码",@"注销账号", nil],
                 [NSArray arrayWithObjects:@"资费说明",@"在线升级",@"访问官网",@"软件名片",@"关于我们",@"帮助中心",@"本地区号设置",@"拨打设置",@"通话记录",nil]
                 ,nil]retain];
    }else{
        rows = [[NSArray arrayWithObjects:
                 [NSArray arrayWithObjects:@"最新优惠",@"推荐好友", nil],
                 [NSArray arrayWithObjects:@"查询余额",@"修改密码",@"注销账号", nil],
                 [NSArray arrayWithObjects:@"资费说明",@"在线升级",@"访问官网",@"关于我们",@"帮助中心",@"本地区号设置",@"拨打设置",@"通话记录",nil]
                 ,nil]retain];
    }
    //,@"通话时间"
    dataTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, self.view.frame.size.height-49-44) style:UITableViewStyleGrouped];
	dataTableView.dataSource = self;
	dataTableView.delegate = self;
	[self.view addSubview:dataTableView];
    NSString* keFuCall=[[NSUserDefaults standardUserDefaults]objectForKey:@"kefuCall"];
    if (keFuCall)
    {
        UIBarButtonItem *rightButton =[[[UIBarButtonItem alloc]initWithTitle:@"呼叫客服"
                                                                       style:UIBarButtonItemStylePlain
                                                                      target:self action:@selector(CallKeFu)]autorelease];
        self.navigationItem.rightBarButtonItem = rightButton;
    }
    
    

}
-(void)viewDidAppear:(BOOL)animated
{
    [self ClearHUD];
    [super viewDidAppear:animated];
}
-(void)CallKeFu
{
    UIWebView*callWebview =[[UIWebView alloc] init];
    NSURL *telURL =[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"kefuCall"]]];// 貌似tel:// 或者 tel: 都行
    [callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
    //记得添加到view上
    [self.view addSubview:callWebview];
    [callWebview release];

}

#pragma mark-查询最新优惠
-(void)queryMore:(int)Type
{
    Request_type = Type;
    /*
	self.HUD = [[[MBProgressHUD alloc] initWithView:self.view]autorelease];
    self.HUD.removeFromSuperViewOnHide = YES;
	[self.view addSubview:self.HUD];
	[self.HUD setLabelFont:[UIFont systemFontOfSize:12]];
	[self.HUD setLabelText:@"正在查询,请稍候..."];
	[self.HUD show:YES];
     */
    [self showInfo:@"正在查询,请稍候..."];
    NSString* mobilePhone=[[NSUserDefaults standardUserDefaults] objectForKey:@"LOGIN_USER_KEY"];
    NSString* pre_MD5=[NSString stringWithFormat:@"%@%d%@%@",mobilePhone,Type,SOFT_ID,@"ysw"];
    
    NSString* MD5Str=[GlobalVar md5Str:pre_MD5];
    ASIFormDataRequest* request;
    if ([GlobalVar sharedInstance].blnUseProxy==YES)
    {
        request=[ASIFormDataRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",origin_url_prefix,@"getmsg.php"]]];
        [request setProxyPort:ProxyPort];
        [request setProxyHost:[GlobalVar getTheBestIp]];
    }else
    {
        request=[ASIFormDataRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",[GlobalVar getTheBestUrl],@"proxy.php"]]];
        [request setPostValue:@"getmsg" forKey:@"act"];
        [request setPostValue:origin_url_prefix forKey:@"apiurl"];
    }
    [request setDelegate:self];
    [request setTimeOutSeconds:30.0f];
    [request setPostValue:mobilePhone forKey:@"mobile"];
    [request setPostValue:SOFT_ID forKey:@"softid"];
    [request setPostValue:[NSString stringWithFormat:@"%d",Type]  forKey:@"type"];
    [request setPostValue:MD5Str forKey:@"md5"];
    [request setPostValue:MULTIAGENTSWITCH forKey:@"multiAgent"];
    [request setPostValue:NETWORKSTATE forKey:@"apn"];
    [request setPostValue:SOFT_VER forKey:@"version"];
    [request setDidFinishSelector:@selector(getMsgSuccess:)];
    [request setDidFailSelector:@selector(getMsgFail:)];
    [request startAsynchronous];
}

//查询信息回调
-(void)getMsgSuccess:(ASIHTTPRequest*)request
{
    [self.HUD hide:YES];
    NSString* result=[request responseString];
    if ([result length]>0)
    {
        if (Request_type == 7 || Request_type == 2 || Request_type == 5 || Request_type == 4 || Request_type == 8){
            NSLog(@"查询信息结果:%@",result);
            NSString* msgCode=[[result componentsSeparatedByString:@"|"]objectAtIndex:0];
            WebView_ViewController *Siliwen_WebView = [[WebView_ViewController alloc] init];
            Siliwen_WebView.Content =@"";
            if (Request_type == 8)
            {
                Siliwen_WebView.ShowTuiJian_Btn = YES;
            }
            
            //
            if ([msgCode isEqualToString:@"1"])
            {
                NSString* value=[[result componentsSeparatedByString:@"|"] objectAtIndex:1];
                value=[self NSScanner:value];
                Siliwen_WebView.Content = value;
                /*
                if (Request_type == 8)
                {
                    Siliwen_WebView.ShowTuiJian_Btn = YES;
                }
                [self.navigationController pushViewController:Siliwen_WebView animated:YES];
                [Siliwen_WebView release];
                Siliwen_WebView = nil;
                 */
            }else
            {
                //iToast *siliwen = [iToast makeText:@"查询失败!"];
                //[siliwen show];
                //WebView_ViewController *Siliwen_WebView = [[WebView_ViewController alloc] init];
                /*
                 Siliwen_WebView.Content =@"";
                if (Request_type == 8)
                {
                    Siliwen_WebView.ShowTuiJian_Btn = YES;
                }
                [self.navigationController pushViewController:Siliwen_WebView animated:YES];
                 [Siliwen_WebView release];
                 Siliwen_WebView = nil;
                 */
            }
            [self.navigationController pushViewController:Siliwen_WebView animated:YES];
            [Siliwen_WebView release];
            Siliwen_WebView = nil;
            
        }

    }
}


-(void)getMsgFail:(ASIHTTPRequest*)request
{
    iToast* toast=[iToast makeText:ERRORCODE];
    [toast show];
    
   
}
#pragma mark-查询余额
-(void)queryMoney
{
    if(![[NSUserDefaults standardUserDefaults] objectForKey:@"LOGIN_USER_NUMBER"])
    {
        UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"提醒" message:@"请先绑定账户在操作." delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确  定", nil];
        [alert show];
        [alert release];
        alert = nil;
        return;
    }
    NSString *Account = [NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"LOGIN_USER_NUMBER"]];
    NSString *UserName = [NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"LOGIN_USER_KEY"]];
    NSString* _prMD5=[NSString stringWithFormat:@"%@%@%@",UserName,SOFT_ID,@"ysw"];
    NSString* MD5Str=[GlobalVar md5Str:_prMD5];
    startTime=[GlobalVar getTimeChuo];
    /*
    self.HUD = [[[MBProgressHUD alloc] initWithView:self.view]autorelease];
    self.HUD.removeFromSuperViewOnHide = YES;
    [self.view addSubview:self.HUD];
    [self.HUD setLabelFont:[UIFont systemFontOfSize:12]];
    [self.HUD setLabelText:@"正在查询,请稍候..."];
    [self.HUD show:YES];
    */
    [self showInfo:@"正在查询,请稍候..."];
    ASIFormDataRequest* request;
    if ([GlobalVar sharedInstance].blnUseProxy==YES)
    {
        request=[ASIFormDataRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",origin_url_prefix,@"balance.php"]]];
        [request setProxyPort:ProxyPort];
        [request setProxyHost:[GlobalVar getTheBestIp]];
    }else
    {
        request=[ASIFormDataRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",[GlobalVar getTheBestUrl],@"proxy.php"]]];
        [request setPostValue:origin_url_prefix forKey:@"apiurl"];
        [request setPostValue:@"balance" forKey:@"act"];
    }
    [request setDelegate:self];
    [request setTimeOutSeconds:TIME_OUT_SECONDS];
    [request setPostValue:UserName forKey:@"mobile"];
    [request setPostValue:Account forKey:@"account"];
    [request setPostValue:SOFT_ID forKey:@"softid"];
    [request setPostValue:MD5Str forKey:@"md5"];
    [request setPostValue:MULTIAGENTSWITCH forKey:@"multiAgent"];
    [request setPostValue:NETWORKSTATE forKey:@"apn"];
    [request setPostValue:SOFT_VER forKey:@"version"];
    [request setDidFinishSelector:@selector(checkBalanceSuccess:)];
    [request setDidFailSelector:@selector(checkBalanceFail:)];
    [request startAsynchronous];

}
//查询余额回调
-(void)checkBalanceSuccess:(ASIHTTPRequest*)request
{
    
    [self.HUD hide:YES];
    NSString* result=[request responseString];
    NSLog(@"查询余额结果:%@",result);
    endTime=[GlobalVar getTimeChuo];
    UInt64 time_cha=[GlobalVar preRequestTime:startTime AndAfterRequestTime:endTime];
     NSString* recod=[NSString stringWithFormat:@"\n%@|%d|%@|balance|%@|%@|%@|%llu \n",[GlobalVar getBundleIdentifierAndCurrentDate],[GlobalVar getCarrierNetWorkSignal],[[[[[[request url] absoluteString] componentsSeparatedByString:@"/"] objectAtIndex:2] componentsSeparatedByString:@":"] objectAtIndex:0],SOFT_ID,[GlobalVar getNetWorkStates],[GlobalVar loginUserKey],time_cha];
    NSLog(@"查询余额写入记录:%@",recod);
    [GlobalVar writeTheInfoToTheLocal:recod];
    if ([result length]>0)
    {
        NSArray* arr=[result componentsSeparatedByString:@"|"];
        if ([arr count]==3&& [result rangeOfString:@"|"].location!=NSNotFound)
        {
            //NSString* checkCode=[[result componentsSeparatedByString:@"|"]objectAtIndex:0];
            NSString* checkCode = arr[0];
            if ([checkCode isEqualToString:@"1"])
            {
                //NSString* balance=[[result componentsSeparatedByString:@"|"] objectAtIndex:1];
                //NSString* Valid=[[result componentsSeparatedByString:@"|"]objectAtIndex:2];
                NSString* balance = arr[1];
                NSString* Valid = arr[2];
                NSString *Value=@"";
                if ([balance length]>0)
                {
                    NSString* baoyueOrLiuliangCode=[[NSUserDefaults standardUserDefaults] objectForKey:@"baoyueOrLiuliang"];
                    if ([baoyueOrLiuliangCode isEqualToString:@"0"])
                    {
                        NSString* showMinCode=[[NSUserDefaults standardUserDefaults] objectForKey:@"showMin"];
                        if ([showMinCode isEqualToString:@"0"])
                        {
                            NSRange range1 = [balance rangeOfString:@"分钟"];
                            if (range1.location!=NSNotFound)
                            {
                                Value = [NSString stringWithFormat:@"可用分钟:%@\n\n 有效期:%@",balance,Valid];;
                            }else{
                                Value=[NSString stringWithFormat:@"可用余额:%@元\n\n 有效期:%@",balance,Valid];
                            }
                            //Value=[NSString stringWithFormat:@"可用余额:%@元\n\n 有效期:%@",balance,Valid];
                        }else
                        {
                            NSRange range = [balance rangeOfString:@"分钟"];
                            if (range.location!=NSNotFound)
                            {
                                Value = [NSString stringWithFormat:@"可用分钟:%@\n\n 有效期:%@",balance,Valid];;
                            }else{
                                float balance_FloatValue=[balance floatValue];
                                NSString* rate=[[NSUserDefaults standardUserDefaults] objectForKey:@"rate"];
                                float rate_FloatValue=[rate floatValue];
                                Value=[NSString stringWithFormat:@"可用分钟:%.2f分钟 \n\n 有效期:%@",balance_FloatValue/rate_FloatValue,Valid];
                            }
                        }
                    }else if ([baoyueOrLiuliangCode isEqualToString:@"1"])
                    {
                        if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"CONTENT"] length]>0)
                        {
                            Value=[NSString stringWithFormat:@"%@ \n\n 有效期:%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"CONTENT"],Valid];
                        }else
                        {
                            Value=[NSString stringWithFormat:@"包月 \n\n 有效期:%@",Valid];
                        }
                    }else if (baoyueOrLiuliangCode==nil || [baoyueOrLiuliangCode isEqualToString:@""])
                    {
                        Value=[NSString stringWithFormat:@"可用余额:%@元\n\n 有效期:%@",balance,Valid];
                    }
                    
                    [self ShowYuE:Value];
                    
                }else
                {
                    iToast *siliwen = [iToast makeText:@"查询失败!"];
                    [siliwen show];
                }
            }else{
                
                iToast *siliwen = [iToast makeText:@"查询失败!"];
                [siliwen show];
            }
            
            
        }
    }else
    {

        [GlobalVar writeTheInfoToTheLocal:@"收到数据包为空，重新选线路"];
        [[SocketDispatch sharedInstance] socketCheck];
        [GlobalVar alert:ERRORCODE];
    }
}

-(void)checkBalanceFail:(ASIHTTPRequest*)request
{
    [self.HUD hide:YES];
    [[SocketDispatch sharedInstance] socketCheck];
    [GlobalVar alert:ERRORCODE];
    NSString* time_out_info=[NSString stringWithFormat:@"%@超时 %@",[[[[[[request url] absoluteString] componentsSeparatedByString:@"/"] objectAtIndex:2] componentsSeparatedByString:@":"] objectAtIndex:0],[GlobalVar getBundleIdentifierAndCurrentDate]];
    [GlobalVar writeTheInfoToTheLocal:time_out_info];

}
-(NSString*)NSScanner:(NSString*)str
{
    NSScanner* scanner=[NSScanner scannerWithString:str];
    NSString* text=nil;
    while ([scanner isAtEnd]==NO)
    {
        [scanner scanUpToString:@"\\n" intoString:nil];
        [scanner scanUpToString:@"\n" intoString:&text];
        str=[str stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%@",text] withString:@""];
    }
    return str;
}
-(void)ShowYuE:(NSString *)value
{
    self.HUD = [[[MBProgressHUD alloc] initWithView:self.view]autorelease];
    self.HUD.removeFromSuperViewOnHide = YES;
    [self.HUD setMode:MBProgressHUDModeText];
    [self.view addSubview:self.HUD];
    [self.HUD setDetailsLabelText:value];
    [self.HUD setDetailsLabelFont:[UIFont systemFontOfSize:16]];
    [self.HUD show:YES];
    UITapGestureRecognizer* tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(ClearHUD)];
    [self.HUD addGestureRecognizer:tap];
    [tap  release];
   // [self performSelector:@selector(ClearHUD) withObject:nil afterDelay:3.0f];
    
}
-(void)ClearHUD
{
    if (self.HUD)
    {
        [self.HUD hide:YES];
        self.HUD = nil;
    }
    
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (alertView.tag ==100)
    {
        if (buttonIndex == 0)
        {
            //直拨
            if ([ViewController sharedInstance].sipphone && [ViewController sharedInstance].sipphone.length>0)
            {
               // pjsuaDestroy();
            }
            NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
            [defaults removeObjectForKey:@"LOGIN_USER_KEY"];
            [defaults removeObjectForKey:@"LOGIN_USER_NUMBER"];
            [defaults removeObjectForKey:@"LOGIN_USER_PASS"];
            [defaults removeObjectForKey:@"LOGIN_USER_REPASS"];
            [defaults removeObjectForKey:@"zuixinyouhui"];
            [defaults removeObjectForKey:@"vipName"];
            [defaults removeObjectForKey:@"vipUrl"];
            [defaults synchronize];
            [(AppDelegate*)[UIApplication sharedApplication].delegate logout];
        }
    }else if(alertView.tag == 200)
    {
        if (buttonIndex == 0)
        {
            NSLog(@"updateUrl====:%@",updateUrl);
            NSURL *xurl = [[[NSURL alloc]initWithString:updateUrl]autorelease];
            [[UIApplication sharedApplication] openURL:xurl];
        }
    }
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)aTableView
{
	return rows.count;
}

- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section
{
    return [[rows objectAtIndex:section]count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
	return 40;
}
/*
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    if (section ==0)
    {
        return @"";
    }else if (section ==1)
    {
        return @"账号";
    }else if (section ==3)
    {
        return @"其他";
    }else{
        return @"";
    }
}
*/

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
	NSUInteger row=[indexPath row];
    NSInteger section = [indexPath section];
    static NSString *defaultCellIdentifier = @"defaultCellIdentifier";
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:defaultCellIdentifier];
    if (cell == nil)
    {
        //UITableViewCellStyleDefault
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1
                                       reuseIdentifier:defaultCellIdentifier] autorelease];
        cell.selectionStyle = UITableViewCellSelectionStyleGray;
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    
    NSString *title = [[rows objectAtIndex:section]objectAtIndex:row];
    cell.textLabel.text = title;
    if ([title isEqualToString:@"在线升级"])
    {
        cell.detailTextLabel.text = [GlobalVar getVersion];
    }
    return cell;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
	NSUInteger row =indexPath.row;
    NSInteger section = indexPath.section;
    NSString *title = [[rows objectAtIndex:section]objectAtIndex:row];
    if ([title isEqualToString:@"最新优惠"])
    {
        [self queryMore:7];
    }else if([title isEqualToString:@"推荐好友"])
    {
        [self queryMore:8];
    }else if([title isEqualToString:@"查询余额"])
    {
        [self queryMoney];
    }else if([title isEqualToString:@"账户充值"])
    {
        DisPayViewController* disF=[[[DisPayViewController alloc]init]autorelease];
        [self.navigationController pushViewController:disF animated:YES];
    }else if([title isEqualToString:@"绑定账号"])
    {
        BangDing_ViewControl *Siliwen_BangDing = [[BangDing_ViewControl alloc] init];
        [self.navigationController pushViewController:Siliwen_BangDing animated:YES];
        [Siliwen_BangDing release];
        Siliwen_BangDing = nil;
    }else if([title isEqualToString:@"注销账号"])
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"确认"
                                                        message:@"确定要“注销账号”退出吗?"
                                                       delegate:self
                                              cancelButtonTitle:nil
                                              otherButtonTitles:@"退出",@"取消",nil];
        alert.tag = 100;
        [alert show];
        [alert release];
    }else if([title isEqualToString:@"修改密码"])
    {
        ModiPwdViewController *mpvc = [[[ModiPwdViewController alloc]init]autorelease];
        [self.navigationController pushViewController:mpvc animated:YES];
    }else if([title isEqualToString:@"找回密码"])
    {
        FindPwdViewController *fpvc = [[[FindPwdViewController alloc]init]autorelease];
        [self.navigationController pushViewController:fpvc animated:YES];
    }else if([title isEqualToString:@"资费说明"])
    {
        [self queryMore:2];
    }else if([title isEqualToString:@"在线升级"])
    {
        [self updateVersion];
    }else if([title isEqualToString:@"访问官网"])
    {
        NSString* webStr=@"";
        NSString* webUrlStr=[[NSUserDefaults standardUserDefaults]objectForKey:@"webAdd"];
        if (![webUrlStr hasPrefix:@"http://"]) {
            webStr=[NSString stringWithFormat:@"http://%@",webUrlStr];
        }else
        {
            webStr=webUrlStr;
        }
        
        NSURL* webUrl=[NSURL URLWithString:webStr];
        [[UIApplication sharedApplication] openURL:webUrl];
    }else if([title isEqualToString:@"软件名片"])
    {
        mingpianView=[[[QrCodeView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_W, IPHONE_H)]autorelease];
        [self.view addSubview:mingpianView];
        if ([[[UIDevice currentDevice]systemVersion]floatValue]>=7.0)
        {
            [self  hideTabBarController:self.tabBarController];
        }
        UITapGestureRecognizer* tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(viewRemove)];
        [mingpianView addGestureRecognizer:tap];
        [tap release];
    }else if([title isEqualToString:@"关于我们"])
    {
        [self queryMore:5];
    }else if([title isEqualToString:@"帮助中心"])
    {
        [self queryMore:4];
    }else if([title isEqualToString:@"本地区号设置"])
    {
        LocalDisNumSetViewController* localNum=[[LocalDisNumSetViewController alloc]init];
        [self.navigationController pushViewController:localNum animated:YES];
        [localNum release];
    }else if([title isEqualToString:@"拨打设置"])
    {
        DialSettingViewController* dialSet=[[DialSettingViewController alloc]init];
        [self.navigationController pushViewController:dialSet animated:YES];
        [dialSet release];
    }else if([title isEqualToString:@"通话记录"])
    {
        CallRecordViewController* callRecord=[[CallRecordViewController alloc]init];
        [self.navigationController pushViewController:callRecord animated:YES];
        [callRecord release];
    }else if([title isEqualToString:@"通话时间"])
    {
        RecordCallingTimeViewCtrl* callRecordTime=[[RecordCallingTimeViewCtrl alloc]init];
        [self.navigationController pushViewController:callRecordTime animated:YES];
        [callRecordTime release];
    }
    
    
}
/*
-(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
    if (section==(rows.count-1))
    {
        return [GlobalVar getVersion];
    }
    return @"";
}
 */
-(void)viewRemove
{
    if ([[[UIDevice currentDevice]systemVersion]floatValue]>=7.0)
    {
        [self showTabBarController:self.tabBarController];
    }
    [mingpianView removeFromSuperview];
}

-(void)hideTabBarController:(UITabBarController*)tabBarController
{
    for (UIView* view in tabBarController.view.subviews)
    {
        if ([view isKindOfClass:[UITabBar class]])
        {
            [view setFrame:CGRectMake(view.frame.origin.x,IPHONE_H, IPHONE_W, 49)];
            [dataTableView setFrame:CGRectMake(0, 0, IPHONE_W, IPHONE_H-44)];
        }
    }
}

-(void)showTabBarController:(UITabBarController*)tabBarController
{
    for (UIView* view in tabBarController.view.subviews)
    {
        if ([view isKindOfClass:[UITabBar class]])
        {
            [view setFrame:CGRectMake(view.frame.origin.x,IPHONE_H-49, IPHONE_W, 49)];
            [dataTableView setFrame:CGRectMake(0, 0, IPHONE_W, IPHONE_H-44-49)];
        }
    }
}
//升级
-(void)updateVersion
{
    if(![[NSUserDefaults standardUserDefaults] objectForKey:@"LOGIN_USER_NUMBER"]){
        UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"提醒" message:@"请先绑定账户在操作." delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确  定", nil];
        [alert show];
        [alert release];
        alert = nil;
        return;
    }
    [self showInfo:@"正在查询,请稍候..."];
    NSString *CanShu = [NSString stringWithFormat:@"<root><productid>%@</productid><platform>iphone</platform><version>%@</version></root>",SOFT_ID,SOFT_VER];
    ASIHTTPRequest* request=[ASIHTTPRequest requestWithURL:[NSURL URLWithString:UPDATE_URL]];
    [request setTimeOutSeconds:TIME_OUT_SECONDS];
    [request setDelegate:self];
    if ([GlobalVar sharedInstance].blnUseProxy==YES)
    {
        [request setProxyPort:ProxyPort];
        [request setProxyHost:[GlobalVar getTheBestIp]];//
    }
    [request setPostBody:[NSMutableData dataWithData:[CanShu dataUsingEncoding:NSUTF8StringEncoding]]];
    [request setDidFinishSelector:@selector(updateSuccess:)];
    [request setDidFailSelector:@selector(updateFail:)];
    [request startAsynchronous];
}
-(void)showInfo:(NSString*)info
{
    self.HUD = [[[MBProgressHUD alloc] initWithView:self.view]autorelease];
    self.HUD.removeFromSuperViewOnHide = YES;
    [self.view addSubview:self.HUD];
    [self.HUD setLabelFont:[UIFont systemFontOfSize:12]];
    [self.HUD setLabelText:info];
    [self.HUD show:YES];
}

//升级回调
-(void)updateSuccess:(ASIHTTPRequest*)request
{
    [self.HUD hide:YES];
    NSString* str=[request responseString];
    if([str rangeOfString:@"<code>0</code>"].location != NSNotFound)
    {
        
        int xx = [str rangeOfString:@"<url>"].location;
        NSString *value = [str substringFromIndex:xx];
        xx = [value rangeOfString:@"</url>"].location;
        value = [value substringToIndex:xx];
        value = [value stringByReplacingOccurrencesOfString:@"<url>" withString:@""];
        [updateUrl release];
        updateUrl=[value retain];
        [self.HUD hide:YES];
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"更新"
                                                        message:@"发现新版本，需要更新吗？"
                                                       delegate:self
                                              cancelButtonTitle:nil
                                              otherButtonTitles:@"确定",@"取消",nil];
        alert.tag = 200;
        [alert show];
        [alert release];
    }
    else
    {
        self.HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]] autorelease];
        self.HUD.mode = MBProgressHUDModeCustomView;
        self.HUD.labelText = @"已经是最新版本";
        [self.HUD hide:YES afterDelay:2];
    }
}


//获取自动更新地址失败返回来内容
-(void)updateFail:(ASIHTTPRequest*)request
{
    iToast* toast=[iToast makeText:ERRORCODE];
    [toast show];
}





- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


-(void)dealloc
{
   
    [updateUrl release];
    [rows release];
    [super dealloc];
}


@end



























































































































































































































































































































































































































































































































































































































































































































































































































































































































































































